#include<bits/stdc++.h>
#define int unsigned int
#define N 500005
using namespace std;
int n,m;
int a[N],b[N],c[N],d[N];
int s[N];
int ans;
void dfs(int x){
    if(x>4){
        for(int i=1;i<=m;i++){
            int o=(s[1]>a[i])+(s[2]>b[i])+(s[3]>c[i])+(s[4]>d[i]);
            if(o<3) return;
        }
        ans++;
        return;
    }
    for(int i=1;i<=n;i++) s[x]=i,dfs(x+1);
}
signed main(){
    freopen("c.in","r",stdin);
    freopen("c.out","w",stdout);
    scanf("%u %u",&n,&m);
    for(int i=1;i<=m;i++) scanf("%u %u %u %u",&a[i],&b[i],&c[i],&d[i]);
    dfs(1);
    printf("%u\n",ans);
    return 0;
}